package com.example.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.example.conf.MyConfigPrope;

@RestController
@EnableConfigurationProperties(MyConfigPrope.class)//告诉spring 启动这个配置类
public class HelloController {

	@Value("${testValue}") //直接获取application.propeties里面指定的值
	private String testValue;
	
	@Autowired
	MyConfigPrope myConfigProperties;
	
	@RequestMapping(value="/hello",method=RequestMethod.GET)  //等同于 @GetMapping(value="/hello")
	public String index() {
		return testValue+" Hello World "+myConfigProperties.getAge();
	}
	
	@RequestMapping(value="/hello2/{id}")
	public String index2(@PathVariable("id") Integer id) {
		return testValue+" Hello World "+myConfigProperties.getAge();
	}
	
	@RequestMapping(value= {"/json","/json2"})
	public Object ijson(@RequestParam(value="id",required=true,defaultValue="0") Integer id) {
		return myConfigProperties;
	}
	
}
